package com.tiny.conf.autoconfiguration;

import com.tiny.conf.client.spring.TinyConfFactory;
import com.tiny.conf.core.core.TinyConfLocalCacheConf;
import com.tiny.conf.properties.TinyConfProperties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;

@EnableConfigurationProperties(TinyConfProperties.class)
public class TinyConfAutoConfiguration {
    private static Logger logger = LoggerFactory.getLogger(TinyConfAutoConfiguration.class);

    @Bean
    public TinyConfFactory tinyConfFactory(TinyConfProperties tinyConfProperties) {
        TinyConfFactory tinyConfFactory = new TinyConfFactory();
        tinyConfFactory.setEnv(tinyConfProperties.getEnv());
        tinyConfFactory.setZkaddress(tinyConfProperties.getZkaddress());
        tinyConfFactory.setZkdigest(tinyConfProperties.getZkdigest());

        logger.info("TinyConfFactory init env:{}, zkaddress:{}, zkdigest:{}", tinyConfProperties.getEnv(), tinyConfProperties.getZkaddress(), tinyConfProperties.getZkdigest());
        return tinyConfFactory;
    }
}
